const state = {
  paths: [],
  currentRouter: {}
}

const mutations = {
  SET_PATHS: (state, paths) => {
    state.paths = paths
  },
  SET_SIDERS: (state, currentRouter) => {
    state.currentRouter = currentRouter
  }
}

const actions = {
  setCurrentRouter({ commit }, data) {
    commit('SET_SIDERS', data)
  },
  setPathsFromRouter({ commit, state }, router) {
    const paths = state.paths
    const index = paths.findIndex((item) => router.path === item.path)
    if (index < 0 && !['/', '/login', '/login/'].includes(router.path)) {
      paths.push(router)
      commit('SET_PATHS', paths)
    }
  },
  delPaths({ commit, state }, path) {
    const paths = state.paths
    const index = paths.findIndex((item) => path === item.path)
    paths.splice(index, 1)
    commit('SET_PATHS', paths)
  }
}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}
